Matplotlib Tutorial Part 01: Introduction and Line

Source


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt

Plotting Lines based on points


In [2]:
fig = plt.figure(figsize=(17,9))
X = [1,2,3]
Y = [5,6,1]

#Plotting and Customization
plt.grid(True)
plt.plot(X, Y)
plt.show()


Plotting Points


In [3]:
fig = plt.figure(figsize=(17,9))
X = [1,2,3,4,9,3,7,1,2,8,5]
Y = [5,6,1,1,4,7,5,4,6,8,2]

#Plotting and Customization
plt.grid(True)
plt.plot(X, Y,'.')
plt.show()


Plotting Math Functions


In [4]:
fig = plt.figure(figsize=(17,9))
def f(x):
    return x**2

X = [i for i in range(-10,11)]
Y = [f(x) for x in X]

#Plotting and Customization
plt.grid(True)
plt.plot(X,Y)
plt.show()


Plotting Random points


In [1]:
from random import randint
fig = plt.figure(figsize=(17,9))

amount_points = 30

X = [i for i in range(amount_points)]
Y = [randint(0,9) for i in range(amount_points)]

#Plotting and Customization
plt.grid(True)
plt.plot(X,Y,'.')
plt.show()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-3a745bc046d4> in <module>()
      1 from random import randint
----> 2 fig = plt.figure(figsize=(17,9))
      3 
      4 amount_points = 30
      5 

NameError: name 'plt' is not defined